#pragma once

#include "VariableAction.h"

#include "Variable.h"

namespace uml {

VariableAction::VariableAction(const QString& umlType)
    : Action(umlType) {}

void VariableAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    variable_ = JsonSerializable::create<Variable>(json.value("variable"), errorList);

}

void VariableAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (variable_) {
        QJsonObject variable_json;
        variable_->toJson(variable_json);
        json.insert("variable", variable_json);
    }
}

/// <summary>
/// variable getter
/// The Variable to be read or written.
/// </summary>
shared_ptr<Variable> VariableAction::variable() const {
    return variable_;
}

/// <summary>
/// variable setter
/// The Variable to be read or written.
/// </summary>
void VariableAction::setVariable(shared_ptr<Variable> value) {
    variable_ = value;
}

} // namespace uml
